home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / src / binutils.252 / ld / genscrip.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1994-09-26  |  4.0 KB  |  119 lines

  1. #!/bin/sh
  2. # genscripts.sh - generate the ld-emulation-target specific files
  3. #
  4. # Usage: genscripts.sh srcdir libdir host_alias target_alias \
  5. # default_emulation this_emulation
  6. #
  7. # Sample usage:
  8. # genscripts.sh /djm/ld-devo/devo/ld /usr/local/lib sparc-sun-sunos4.1.3 \
  9. # sparc-sun-sunos4.1.3 sun4 sun3
  10. # produces sun3.x sun3.xbn sun3.xn sun3.xr sun3.xu em_sun3.c
  11.  
  12. srcdir=$1
  13. libdir=$2
  14. host_alias=$3
  15. target_alias=$4
  16. DEFAULT_EMULATION=$5
  17. NATIVE_LIB_DIRS=$6
  18. EMULATION_NAME=$7
  19.  
  20. # Include the emulation-specific parameters:
  21. . ${srcdir}/emulparams/${EMULATION_NAME}.sh
  22.  
  23. # Set the library search path, for libraries named by -lfoo.
  24. # If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used.
  25. # Otherwise, the default is set here.
  26. #
  27. # The format is the usual list of colon-separated directories.
  28. # To force a logically empty LIB_PATH, do LIBPATH=":".
  29.  
  30. if [ "x${LIB_PATH}" = "x" ] ; then
  31.    if [ "x${host_alias}" = "x${target_alias}" ] ; then
  32.       # Native.
  33.       LIB_PATH=/lib:/usr/lib
  34.       if [ -n "${NATIVE_LIB_DIRS}" ]; then
  35.     LIB_PATH=${LIB_PATH}:${NATIVE_LIB_DIRS}
  36.       fi
  37.       LIB_PATH=${LIB_PATH}:${libdir}
  38.       if [ "${libdir}" != /usr/local/lib ] ; then
  39.         LIB_PATH=${LIB_PATH}:/usr/local/lib
  40.       fi
  41.    else
  42.       # Cross.
  43.       LIB_PATH=
  44.    fi
  45. fi
  46.  
  47. # Always search $(tooldir)/lib, aka /usr/local/TARGET/lib.
  48. LIB_PATH=${LIB_PATH}:`echo ${libdir} | sed -e s'|/lib$||'`/${target_alias}/lib
  49.  
  50. LIB_SEARCH_DIRS=`echo ${LIB_PATH} | tr ':' ' ' | sed -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\1);/g'`
  51.  
  52. # Generate 5 or 6 script files from a master script template in
  53. # ${srcdir}/scripttempl/${SCRIPT_NAME}.sh.  Which one of the 5 or 6
  54. # script files is actually used depends on command line options given
  55. # to ld.  (SCRIPT_NAME was set in the emulparams_file.)
  56. #
  57. # A .x script file is the default script.
  58. # A .xr script is for linking without relocation (-r flag).
  59. # A .xu script is like .xr, but *do* create constructors (-Ur flag).
  60. # A .xn script is for linking with -n flag (mix text and data on same page).
  61. # A .xbn script is for linking with -N flag (mix text and data on same page).
  62. # A .xs script is for generating a shared library with the --shared
  63. #   flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the
  64. #   emulation parameters.
  65.  
  66. SEGMENT_SIZE=${SEGMENT_SIZE-${PAGE_SIZE}}
  67.  
  68. # Determine DATA_ALIGNMENT for the 5 variants, using
  69. # values specified in the emulparams/<emulation>.sh file or default.
  70.  
  71. DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}"
  72. DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}"
  73. DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}"
  74. DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}"
  75. DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}"
  76.  
  77. LD_FLAG=r
  78. DATA_ALIGNMENT=${DATA_ALIGNMENT_r}
  79. DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})"
  80. (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
  81.   ldscripts/${EMULATION_NAME}.xr
  82.  
  83. LD_FLAG=u
  84. DATA_ALIGNMENT=${DATA_ALIGNMENT_u}
  85. CONSTRUCTING=" "
  86. (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
  87.   ldscripts/${EMULATION_NAME}.xu
  88.  
  89. LD_FLAG=
  90. DATA_ALIGNMENT=${DATA_ALIGNMENT_}
  91. RELOCATING=" "
  92. (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
  93.   ldscripts/${EMULATION_NAME}.x
  94.  
  95. LD_FLAG=n
  96. DATA_ALIGNMENT=${DATA_ALIGNMENT_n}
  97. TEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}}
  98. (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
  99.   ldscripts/${EMULATION_NAME}.xn
  100.  
  101. LD_FLAG=N
  102. DATA_ALIGNMENT=${DATA_ALIGNMENT_N}
  103. (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
  104.   ldscripts/${EMULATION_NAME}.xbn
  105.  
  106. if test -n "$GENERATE_SHLIB_SCRIPT"; then
  107.   LD_FLAG=shared
  108.   DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
  109.   CREATE_SHLIB=" "
  110.   # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
  111.   (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
  112.     ldscripts/${EMULATION_NAME}.xs
  113. fi
  114.  
  115. test "$DEFAULT_EMULATION" = "$EMULATION_NAME" && COMPILE_IN=true
  116.  
  117. # Generate em_${EMULATION_NAME}.c.
  118. . ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em
  119.